package com.wq.payunion.oauth2.useroauth2.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @Author: wangqiang20995
 * @Date:2018 年 9 月 16 日 0016
 * @Description:
 * @Resource:
 */
@Component
public class ApplicationContextUtils implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ApplicationContextUtils.applicationContext = applicationContext;
    }

    public static <T> T getBean(String bean,Class<T> target){
        if(applicationContext == null){
            return null;
        }
        return (T) applicationContext.getBean(bean);
    }
}
